# -*- coding: utf-8 -*-
import tkinter as tk  # 使用Tkinter前需要先导入
from tkinter import messagebox
from Utils import Dormancy
import os

class PowerManage:
    def __init__(self):
        root_user =  (os.getgid() == 0 and True or False)
        if not root_user:
            messagebox.showerror("错误","请使用管理员权限启动")
            exit()

    def main(self):
        window = tk.Tk()
        window.title('银河麒麟操作系统电源管理自动化测试')
        # 第3步，设定窗口的大小(长 * 宽)
        window.geometry('500x500+600+400')  # 这里的乘是小x
        change_list = tk.IntVar()
        label_nums = tk.Label(text="测试次数：", font=("黑体", 16))
        nums_ = tk.Entry(font=("黑体", 14), width=10)
        sleep_ = tk.Radiobutton(text="睡眠", variable=change_list, value=1, font=("黑体", 12))
        dormancy_ = tk.Radiobutton(text="休眠", variable=change_list, value=2, font=("黑体", 12))  # 睡眠
        reboot_ = tk.Radiobutton(text="重启", variable=change_list, value=3, font=("黑体", 12))  # 重启

        def command_(num):
            if change_list.get() == 2:
                Dormancy.Dormancy(num)
        start_button = tk.Button(text="开始", font=("黑体", 16), width=30,command= lambda :command_(int(nums_.get())))

        log_show = tk.Text(width=60, height=15)
        label_nums.place(x=20, y=30)
        nums_.place(x=130, y=30)
        sleep_.place(x=50, y=100)
        dormancy_.place(x=180, y=100)
        reboot_.place(x=280, y=100)
        start_button.place(x=50, y=150)
        log_show.place(x=10, y=220)
        window.mainloop()


if __name__ == '__main__':
    ss = PowerManage()
    ss.main()
